package one.undefined.Listeners.Interactions;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import java.awt.Color;

import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class GuildInfoCommand extends ListenerAdapter {
    @Override
    public void onSlashCommand(SlashCommandEvent event)
    {
        if(!event.getName().equals("guildinfo")) return;
        DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy")
                .withZone(ZoneId.systemDefault());

        Guild guild = event.getGuild();

        EmbedBuilder embed = new EmbedBuilder()
                .setTitle(guild.getName())
                .setDescription("Владелец: <@" + guild.getOwnerId() + ">"
                        + "\nРолей: **" + guild.getRoles().toArray().length + "**"
                        + "\nДата создания: **" + DATE_TIME_FORMATTER.format(guild.getTimeCreated()) + "**"
                        + "\nУчастников: **" + guild.getMemberCount() + "**"
                )
                .setThumbnail(guild.getIconUrl())
                .setColor(Color.decode("#A09AE7"));
        event.replyEmbeds(embed.build())
                .queue();
    }
}
